ccR.Player = {
	Can = {	Attack = function(unit) return ccR.Player.CanAttack(unit) end },
	CanAttack = function(unit) return ccR.Unit.Is.Attackable("player", unit) end,
	Class = function() return ccR.Unit.Class("player") end,
	Count = function(yards) return ccR.Unit.Count("player", yards) end,
	Friendly_Count = function(yards) return ccR.Unit.Fiendly_Count("player", yards) end,
	CombatCount = function() local vInCombatCount = 0 for x = 1, # ccR_Enemies_Within_44 do local vObject = ccR_Enemies_Within_44[x] if ccR.Unit.Exists(vObject) and ccR.Unit.IsAlive(vObject) and (ccR.Unit.IsTappedByPlayer(vObject) or ccR.Unit.TargetName(vObject) == ccR.Player.Name()) then vInCombatCount = vInCombatCount + 1 end end return vInCombatCount end,
	Distance = function(unit) if unit == nil then unit = "target" end if ccR.Unit.Exists(unit) then return ccR.Unit.Distance(unit, "player") end end,
	Eclipse = function() return GetEclipseDirection() end,
	Enemies = function() return #ccR_Enemies_In_Combat end,
	EnergyRegen = function() return select(2, GetPowerRegen("player")) end,
	EnergyTimeToMax = function() local max = UnitPowerMax("player", 3) local curr = UnitPower("player", 3) local regen = select(2, GetPowerRegen("player")) return (max - curr) * (1.0 / regen)	end,
	FallingTime = function() return ccR.Var("Player_Falling_Duration") end,
	GUID = function() return ccR.Unit.GUID("player") end,
	Health = function(sort) return ccR.Unit.Health("player", sort) end,
	Level = function() return ccR.Unit.Level("player") end,
	Mana = function(sort) return ccR.Unit.Mana("player", sort) end,
	MovingTime = function() return ccR.Var("Player_Moving_Duration") end,
	Name = function() return ccR.Unit.Name("player") end,
	Race = function() return ccR.Unit.Race("player") end,
	Realm = function() return ccR.Unit.Realm("player") end,
	Specialization = function() if GetSpecialization() ~= nil then return GetSpecialization() else return "LowLevel" end end,
	Specialization_Name = function() local id, name = GetSpecializationInfo(GetSpecialization()) return name end,
	Stance = function() return GetShapeshiftForm() end,
	TargetName = function() return ccR.Unit.TargetName("player") end,
	TimeToDie = function() return ccR.Unit.TimeToDie("player") end,
	Threat = function(unit) isTanking, status, scaledPercent, rawPercent, threatValue = UnitDetailedThreatSituation("player", unit) return scaledPercent end,
	Aura = {
		Duration = function(aura, by, number) return ccR.Unit.Aura.Duration("player", aura, by, number) end,
		Exists = function(aura) return ccR.Unit.Aura.Exists("player", aura) end,
		Stacks = function(aura) return ccR.Unit.Aura.Stacks("player", aura) end,
	},
	Buff = {
		Duration = function(buff, by, number) return ccR.Unit.Buff.Duration("player", buff, by, number) end,
		Exists = function(buff) return ccR.Unit.Buff.Exists("player", buff) end,
		Stacks = function(buff) return ccR.Unit.Buff.Stacks("player", buff) end,
	},
	Debuff = {
		Duration = function(debuff, by, number) return ccR.Unit.Debuff.Duration("player", debuff, by, number) end,
		Exists = function(debuff) return ccR.Unit.Debuff.Exists("player", debuff) end,
		Stacks = function(debuff) return ccR.Unit.Debuff.Stacks("player", debuff) end,
	},
	Features = function()
		if (IsFlying() and IsMounted()) then return end
		-- Health Potions
		if ccR.Var("Use_Health_Potions") then ccR.Auto.Health_Potions() end
		-- Health Potions
		if ccR.Var("Use_Health_Potions") then ccR.Auto.Health_Potions() end
		-- Mana Potions
		if ccR.Var("Use_Mana_Potions") then ccR.Auto.Health_Potions() end
		-- Auto Open
		if ccR.Var("Use_Auto_Open") then ccR.Auto.Open() end
		-- Auto Loot
		if ccR.Var("Use_Auto_Loot") then ccR.Auto.Loot() end
		-- Auto Skin
		if ccR.Var("Use_Auto_Skin") then ccR.Auto.Skin() end
		-- Class Specific
		if ccR.Player.Class() == "Death Knight" then
			if ccR.Death_Knight ~= nil then
				if ccR.Var("Deaths_Advance") then ccR.Death_Knight.Talent.Deaths_Advance() end
			end
		end
		if ccR.Player.Class() == "Rogue" then
			if ccR.Rogue ~= nil then
				if ccR.Var("Auto_Stealth") then ccR.Rogue.Feature.Auto_Stealth() end
				if ccR.Var("Auto_Burst_of_Speed") then ccR.Rogue.Feature.Auto_Burst_of_Speed() end
				if ccR.Var("Auto_Recuperate") then ccR.Rogue.Feature.Recuperate(ccR.Var("Recuperate_HP")) end
				if ccR.Var("Auto_TricksoftheTrade") then ccR.Rogue.Feature.Tricks_of_the_Trade() end
			end
		end
		if ccR.Player.Class() == "Monk" then
			if ccR.Monk ~= nil then
				if ccR.Var("Nimble_Brew") then ccR.Monk.Features.Nimble_Brew() end
			end
		end
		if ccR.Player.Class() == "Priest" then
			if ccR.Priest ~= nil then
				if ccR.Var("Angelic_Feather") then ccR.Priest.Talent.Angelic_Feather() end
			end
		end
		if ccR.Player.Class() == "Hunter" then
			if ccR.Hunter ~= nil then
				if ccR.Var("Aspect_of_the_Cheetah") then ccR.Hunter.Aspect_of_the_Cheetah() end
			end
		end
		if ccR.Player.Class() == "Mage" then
			if ccR.Mage ~= nil then
				if ccR.Var("Slow_Fall") then ccR.Mage.Slow_Fall() end
			end
		end
	end,
	Has = {
		Aura = function(aura) return ccR.Unit.Has.Aura("player", aura) end,
		Buff = function(buff) return ccR.Player.Buff.Exists(buff) end,
		Debuff = function(debuff) return ccR.Player.Debuff.Exists(debuff) end,
		Engineering = function() local Engineering = GetSpellInfo(158739) if IsUsableSpell(Engineering) then return true else return false end end,
		Glyph = function(glyphid) if glyphid ~= nil then for slot = 1, NUM_GLYPH_SLOTS do local _, _, _, glyphSpellID = GetGlyphSocketInfo(slot) if glyphid == glyphSpellID then	return true	end end	return false else ccR.Error("ccR.Player.Has.Glyph(nil)") return false end end,
		Herbalism = function() local Gathering = GetSpellInfo(158745) if IsUsableSpell(Gathering) then return true else return false end end,
		Heroism = function() if ccR.Player.Has.Buff(BLOODLUST) or ccR.Player.Has.Buff(HEROISM) or ccR.Player.Has.Buff(TIME_WARP) or ccR.Player.Has.Buff(ANCIENT_HYSTERIA) or ccR.Player.Has.Buff(NETHERWINDS) then return true else return false end end,
		LeftOnCast = function(time) return ccR.Unit.Has.LeftOnCast("player", time) end,
		LeftOnChannel = function(time) return ccR.Unit.Has.LeftOnChannel("player", time) end,
		Mining = function()	local Mining = GetSpellInfo(2656) if IsUsableSpell(Mining) then return true else return false	end end,
		Morphing_Spell = function(spell)
			--if tonumber(spell) ~= nil then spell = GetSpellInfo(spell) end
			if spellBook:GetSpellInfo(spell) ~= nil then
				return true
			else
				return false
			end			
		end,
		Spell = 
		function(spell, ignoreUsable)
			if ignoreUsable == nil then ignoreUsable = false end
			-- Check General
			if tonumber(spell) ~= nil then spell = GetSpellInfo(spell) end
			local _, _, offset, numSpells, _, _ = GetSpellTabInfo(1);
			for thisIndex = offset+1, numSpells+offset do
				if spell == GetSpellBookItemName(thisIndex, "spell")
				and (ignoreUsable or (not ignoreUsable and IsUsableSpell(thisIndex, "spell")))
				then 
					return true
				end
			end	
			-- Check active spec
			local _, _, offset, numSpells, _, _ = GetSpellTabInfo(2);
			for thisIndex = offset+1, numSpells+offset do
				if spell == GetSpellBookItemName(thisIndex, "spell")
				and (ignoreUsable or (not ignoreUsable and IsUsableSpell(thisIndex, "spell")))
				then 
					return true
				end
			end	
			-- Check Flyouts
			for f = 1, GetNumFlyouts() do
				local flyoutID = GetFlyoutID(f)
				local _, _, numSlots, isKnown = GetFlyoutInfo(flyoutID)
				if isKnown and numSlots > 0 then
					for s = 1, numSlots do
						local spellID, _, isKnownSpell = GetFlyoutSlotInfo(flyoutID, s)
						local name = GetSpellInfo(spellID)
						if name == spell and isKnownSpell then
							return true
						end
					end
				end
		  	end			
		  	-- Check Pet
			local numPetSpells = HasPetSpells();
			if numPetSpells then
				for thisIndex = 1, numPetSpells do
					if spell == GetSpellBookItemName(thisIndex, "pet") then
						if spell == GetSpellBookItemName(thisIndex, "pet")
						and (ignoreUsable or (not ignoreUsable and IsUsableSpell(thisIndex, "pet")))
						then 
							return true
						end
					end
				end
			end		  	
			return false
		end,
		Skinning = function() local Gathering = GetSpellInfo(102216) if IsUsableSpell(Gathering) then return true else return false	end end,
		Statue = function(name) return ccR.Player.Statue.Exists(name) end,
		Talent = function(spell) return ccR.Player.Has.Spell(spell, true) end,
		Target = function() return ccR.Unit.Has.Target("player") end,
		Totem = function(name) return ccR.Player.Totem.Exists(name) end,
	},
	Is = {
		Alive = function() return ccR.Unit.Is.Alive("player") end,
		Behind = function(unit) if ccR.Unit.Exists(unit) then local PlayerX, PlayerY = ObjectPosition("player"); local X, Y, Z = ObjectPosition(unit); local Rotation = ObjectFacing(unit); if ObjectType(unit) == 9 and ccR.Unit.HasTarget(unit) and ccR.Unit.Exists(ccR.Unit.TargetName(unit)) then local tX, tY, tZ = ObjectPosition(ccR.Unit.TargetName(unit)) Rotation = (rad(atan2(Y - tY, X - tX)) + math.pi) % (math.pi * 2); end	return ((PlayerX - X) * math.cos(-Rotation)) - ((PlayerY - Y) * math.sin(-Rotation)) < 0; end end,
		Caster = function() local vClass = ccR.Player.Class(); local vSpec = ccR.Player.Specialization() if vClass == "Mage" or vClass == "Warlock" or (vClass == "Paladin" and vSpec == 1 ) or (vClass == "Shaman" and (vSpec == 1 or vSpec == 3 )) or vClass == "Priest" or (vClass == "Druid" and vSpec == 4 ) or (vClass == "Monk" and vSpec == 2 ) then return true else return false end end,
		Casting = function() return ccR.Unit.Is.Casting("player") end,
		CastingSpell = function(spell) return ccR.Unit.Is.CastingSpell("player", spell) end,
		CastingOrChanneling = function() if ccR.Player.Is.Casting() or ccR.Player.IsChanneling() then return true else return false end end,
		Channeling = function() return ccR.Unit.Is.Channeling("player") end,
		ChannelingSpell = function(spell) return ccR.Unit.Is.ChannelingSpell("player", spell) end,
		Dead = function() return ccR.Unit.Is.Dead("player") end,
		DPS = function() return ccR.Unit.Is.DPS("player") end,
		ExactFacing = function(unit) if unit == nil then unit = "target" end return ccR.Unit.Is.ExactFacing("player", unit)	end,
		Facing = function(unit) if unit == nil then unit = "target" end if ccR.Unit.Exists(unit) then return ccR.Unit.Is.Facing("player", unit) end end,
		Falling = function() if IsFalling() then return true else return false end end,
		Flying = function() if IsFlying() then return true else return false end end,
		Frozen = function() return ccR.Unit.Is.Frozen("player") end,
		Ghost = function() return UnitIsGhost("player") end,
		Healer = function() return ccR.Unit.Is.Healer("player") end,
		In = {
			Combat = function() return ccR.Unit.Is.InCombat("player") end,
			Group = function() return IsInGroup() end,
			Arena = function() inInstance, instanceType = IsInInstance() if inInstance and instanceType == "arena" then return true else return false end end,
			Raid = function() inInstance, instanceType = IsInInstance() if inInstance and instanceType == "raid" and GetNumGroupMembers() >= 1 then return true else return false end end,
			Dungeon = function() inInstance, instanceType = IsInInstance() if inInstance and instanceType == "party" and GetNumGroupMembers() >= 1 then return true else return false end end,
			PVP = function() inInstance, instanceType = IsInInstance() if inInstance and instanceType == "pvp" then return true else return false end end,
			Scenario = function() inInstance, instanceType = IsInInstance() if inInstance and (instanceType == nil or instanceType == "scenario") then return true else return false end end,
			Stealth = function() return IsStealthed() end,
		},
		InCombat = function() return ccR.Unit.Is.InCombat("player") end,
		InGroup = function() return IsInGroup() end,
		InArena = function() return ccR.Player.Is.In.Arena() end,
		InRaid = function() return ccR.Player.Is.In.Raid() end,
		InDungeon = function() return ccR.Player.Is.In.Dungeon() end,
		InPVP = function() return ccR.Player.Is.In.PVP() end,
		InScenario = function() return ccR.Player.Is.In.Scenario() end,
		InStealth = function() return ccR.Player.Is.In.Stealth() end,
		Lunar = function() return ccR.Player.Has.Spell(MOONFIRE) end,
		Melee = function() local vClass = ccR.Player.Class(); local vSpec = ccR.Player.Specialization() if (vClass == "Paladin" and (vSpec == 2 or vSpec == 3 or vSpec == "LowLevel")) or vClass == "Rogue" or vClass == "Death Knight" or (vClass == "Shaman" and (vSpec == 2 or vSpec == "LowLevel")) or vClass == "Warrior" or (vClass == "Druid" and (vSpec == 2 or vSpec == 3 or vSpec == "LowLevel")) or (vClass == "Monk" and (vSpec == 1 or vSpec == 3 or vSpec == "LowLevel")) then return true else return false end end,
		Moving = function() return ccR.Unit.Is.Moving("player") end,
		Mounted =
		function()
			if IsMounted()
			and not ccR.Player.Has.Buff(164222) -- Frostwolf War Wolf
			and not ccR.Player.Has.Buff(165803) -- Telaari Talbuk
			then
				return true
			else
				return false
			end
		end,
		Ranged = function() local vClass = ccR.Player.Class(); local vSpec = ccR.Player.Specialization() if vClass == "Hunter" or vClass == "Mage" or vClass == "Warlock" or (vClass == "Shaman" and (vSpec == 1 or vSpec == 3)) or (vClass == "Druid" and (vSpec == 1 or vSpec == 4)) or vClass == "Priest" then return true	else return false end end,
		Solo = function() inInstance, instanceType = IsInInstance() if (not inInstance or (inInstance and (not ccR.Player.Is.InGroup() or instanceType == "scenario"))) then return true else return false end end,
		Solar = function() return ccR.Player.Has.Spell(SUNFIRE) end,
		Swimming = function() return IsSwimming() end,
		Tank = function() return ccR.Unit.Is.Tank("player") end,
		Tanking = function(unit) isTanking, status, scaledPercent, rawPercent, threatValue = UnitDetailedThreatSituation("player", unit) return isTanking end,
		Visible = function() return ccR.Unit.Is.Visible("player") end,
		VisibleOnScreen = function() return ccR.Unit.Is.VisibleOnScreen("player") end,
	},
	Statue = {
		Distance = function(name, unit) if ccR.Player.Statue.Exists(name) and ccR.Unit.Exists(unit) then if # ccR_Totems > 0 then for x = 1, # ccR_Totems do if ((tonumber(name) == nil and ccR.Unit.Name(ccR_Totems[x]) == name) or (tonumber(name) ~= nil and ccR.Unit.NPCID(ccR_Totems[x]) == name)) and ccR.Unit.GUID(UnitCreator(ccR_Totems[x])) == ccR.Player.GUID() then return ccR.Unit.Distance(unit, ccR_Totems[x]) end end end else return 99999 end	end,
		Exists = function(name) if # ccR_Totems > 0 then for x = 1, # ccR_Totems do if ((tonumber(name) == nil and ccR.Unit.Name(ccR_Totems[x]) == name) or (tonumber(name) ~= nil and ccR.Unit.NPCID(ccR_Totems[x]) == name)) and ccR.Unit.GUID(UnitCreator(ccR_Totems[x])) == ccR.Player.GUID() then return true	end	end end	return false end,
	},
	Crystal = {
		Exists = 
		function()
			for x = 1, #ccR_Enemies do
				local vUnit = ccR_Enemies[x]
				if ccR.Unit.NPCID(vUnit) == 76933
				and ccR.Unit.Is.Attackable(vUnit)
				then
					return true
				end
			end
			return false
		end,
		Target =
		function()
			for x = 1, #ccR_Enemies do
				local vUnit = ccR_Enemies[x]
				if ccR.Unit.NPCID(vUnit) == 76933
				and ccR.Unit.Is.Attackable(vUnit)
				then
					TargetUnit(vUnit)
					return
				end
			end			
		end,
	},
	Totem = {
		Distance = function(name, unit) if tonumber(name) ~= nil then name = GetSpellInfo(name) end if ccR.Player.Has.Totem(name) and ccR.Unit.Exists(unit) then if # ccR_Totems > 0 then for x = 1, # ccR_Totems do if ccR.Unit.Name(ccR_Totems[x]) == name	and ccR.Unit.GUID(UnitCreator(ccR_Totems[x])) == ccR.Player.GUID() then return ccR.Unit.Distance(unit, ccR_Totems[x]) end end end else return 99999 end	end,
		Duration = function(slot) local haveTotem, name, startTime, duration, icon = GetTotemInfo(slot) if haveTotem then return duration-(startTime-GetTime())*-1 else return 0 end end,
		Exists = 
		function(name) 
			if tonumber(name) ~= nil then name = GetSpellInfo(name) end 
			if # ccR_Totems > 0 then
				for x = 1, # ccR_Totems do
					local vTotem = ccR_Totems[x] 
					if ccR.Unit.Name(vTotem) == name and ccR.Unit.GUID(UnitCreator(vTotem)) == ccR.Player.GUID() then return true end
				end
				return false
			else
				return false
			end
		end,
	},
	-- Unit Power
		Power = function() return UnitPower("player") end,
		Chi = function() return ccR.Player.Light_Force() end,
		MaxChi = function() if ccR.Player.Has.Talent(ASCENSION) then return 5 else return 4 end end,
		Rage = function() return UnitPower("player", 1) end,
		Focus = function() return UnitPower("player", 2) end,
		Energy = function() return UnitPower("player", 3) end,
		Rune = {
			Count = function(runeType) return ccR.Player.Rune_Count(runeType) end,
			Cooldown = function(rune) return ccR.Player.Rune_Cooldown(rune) end,
		},
		Rune_Count = function(runeType) if runeType == "Blood" or runeType == "blood" or runeType == 1 then	runeType = 1; elseif runeType == "Unholy" or runeType == "unholy" or runeType == 2 then runeType = 2; elseif runeType == "Frost" or runeType == "frost" or runeType == 3 then	runeType = 3; elseif runeType == "Death" or runeType == "death" or runeType == 4 then runeType = 4; end local count = 0; for i = 1, 6 do	if GetRuneType(i) == runeType and select(3, GetRuneCooldown(i)) == true then count = count + 1; end end return count; end,
		Rune_Cooldown =	function(rune) if GetRuneCooldown(rune) > 0 then return select(2, GetRuneCooldown(rune)) - (GetTime() - GetRuneCooldown(rune)) end return 0 end,
		Runic_Power = function() return UnitPower("player", 6) end,
		Soul_Shards = function() return UnitPower("player", 7) end,
		Eclipse = function() return UnitPower("player", 8) end,
		Holy_Power = function() return UnitPower("player", 9) end,
		Alternate_Power = function() return UnitPower("player", 10) end,
		Dark_Force = function() return UnitPower("player", 11) end,
		Light_Force = function() return UnitPower("player", 12) end,	-- Seems this is Monk Chi
		Shadow_Orbs = function() return UnitPower("player", 13) end,
		Burning_Embers = function() return UnitPower("player", 14, true) end,
		Demonic_Fury = function() return UnitPower("player", 15) end,
		Combo_Points = 
		function()
			if UnitInVehicle("player") then return 0 end
			if ccR.Target.Is.Attackable() then
				return GetComboPoints("player", "target")
			else
				for Index = 1, ObjectCount() do
					local Object = ObjectWithIndex(Index);
					if bit.band(ObjectType(Object), ObjectTypes.Unit) > 0 then
						if ccR.Unit.Exists(Object)
						and ccR.Unit.Is.Attackable(Object)
						then
							return GetComboPoints("player", Object)
						end
					end
				end
				return 0
			end
		end,

		-- Shortened
		RC = function(runeType) return ccR.Player.Rune.Count(runeType) end,
		RCD = function(rune) return ccR.Player.Rune.Cooldown(rune) end,
		RP = function() return ccR.Player.Runic_Power() end,
		SS = function() return ccR.Player.Soul_Shards() end,
		HP = function() return ccR.Player.Holy_Power() end,
		SO = function() return ccR.Player.Shardow_Orbs() end,
		BE = function() return ccR.Player.BE() end,
		Fury = function() return ccR.Player.Demonic_Fury() end,
		DF = function() return ccR.Player.Demonic_Fury() end,
		CP = function() return ccR.Player.Combo_Points() end,
	---------
	-- OLD --
	---------
		BuffStacks = function(buff) return ccR.Player.Buff.Stacks(buff) end,
		BuffDuration = function(buff) return ccR.Player.Buff.Duration(buff) end,
		DebuffStacks = function(debuff) return ccR.Player.Debuff.Stacks(debuff) end,
		DebuffDuration = function(debuff) return ccR.Player.Debuff.Duration(debuff) end,
		HasBuff = function(buff) return ccR.Player.Has.Buff(buff) end,
		HasDebuff = function(debuff) return ccR.Player.Has.Debuff(debuff) end,
		HasGlyph = function(glyphid) return ccR.Player.Has.Glyph(glyphid) end,
		HasLeftOnCast = function(time) return ccR.Player.Has.LeftOnCast(time) end,
		HasLeftOnChannel = function(time) return ccR.Player.Has.LeftOnChannel(time) end,
		HasSpell = function(spell) return ccR.Player.Has.Spell(spell) end,
		HasTalent = function(spell) return ccR.Player.Has.Talent(spell) end,
		HasTarget = function() return ccR.Player.Has.Target() end,
		HasTotem = function(name) return ccR.Player.Totem.Exists(name) end,
		IsAlive = function() return ccR.Player.Is.Alive() end,
		IsBehind = function(unit) return ccR.Player.Is.Behind(unit) end,
		IsCasting = function() return ccR.Player.Is.Casting() end,
		IsCastingSpell = function(spell) return ccR.Player.Is.CastingSpell(spell) end,
		IsCastingOrChanneling = function() return ccR.Player.Is.CastingOrChanneling() end,
		IsChanneling = function() return ccR.Player.Is.Channeling() end,
		IsChannelingSpell = function(spell) return ccR.Player.Is.ChannelingSpell(spell) end,
		IsDead = function() return ccR.Player.Is.Dead() end,
		IsDPS = function() return ccR.Player.Is.DPS() end,
		IsFacing = function(unit) return ccR.Player.Is.Facing(unit) end,
		IsGhost = function() return ccR.Player.Is.Ghost() end,
		IsHealer = function() return ccR.Player.Is.Healer() end,
		IsInCombat = function() return ccR.Player.Is.InCombat() end,
		IsInGroup = function() return ccR.Player.Is.InGroup() end,
		IsInRaid = function() return ccR.Player.Is.InRaid() end,
		IsInStealth = function() return ccR.Player.Is.InStealth() end,
		IsMelee = function() return ccR.Player.Is.Melee() end,
		IsMoving = function() return ccR.Player.Is.Moving() end,
		IsRanged = function() return ccR.Player.Is.Ranged() end,
		IsSolo = function() return ccR.Player.Is.Solo() end,
		IsTank = function() return ccR.Player.Is.Tank() end,
		TotemDistance = function(name, unit) return ccR.Player.Totem.Distance(name, unit) end,
		TotemDuration = function(slot) return ccR.Player.Totem.Duration(slot) end,
}